package com.prod.web.controller.shop;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.prod.system.domain.TShop;
import com.prod.system.service.ITShopService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.prod.common.annotation.Log;
import com.prod.common.core.controller.BaseController;
import com.prod.common.core.domain.AjaxResult;
import com.prod.common.enums.BusinessType;
import com.prod.common.utils.poi.ExcelUtil;
import com.prod.common.core.page.TableDataInfo;

/**
 * 店铺列表Controller
 *
 * @author zhw
 * @date 2024-05-09
 */
@RestController
@RequestMapping("/shop/shop")
public class TShopController extends BaseController {
    @Autowired
    private ITShopService tShopService;

    /**
     * 查询店铺列表列表
     */
    @PreAuthorize("@ss.hasPermi('shop:shop:list')")
    @GetMapping("/list")
    public TableDataInfo list(TShop tShop) {
        startPage();
        List<TShop> list = tShopService.selectTShopList(tShop);
        return getDataTable(list);
    }

    /**
     * 导出店铺列表列表
     */
    @PreAuthorize("@ss.hasPermi('shop:shop:export')")
    @Log(title = "店铺列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TShop tShop) {
        List<TShop> list = tShopService.selectTShopList(tShop);
        ExcelUtil<TShop> util = new ExcelUtil<TShop>(TShop.class);
        util.exportExcel(response, list, "店铺列表数据");
    }

    /**
     * 获取店铺列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:shop:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tShopService.selectTShopById(id));
    }

    /**
     * 新增店铺列表
     */
    @PreAuthorize("@ss.hasPermi('shop:shop:add')")
    @Log(title = "店铺列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TShop tShop) {
        tShop.setCreateBy(getUsername());
        tShop.setUserId(getUserId());
        tShop.setDeptId(getDeptId());
        return toAjax(tShopService.insertTShop(tShop));
    }

    /**
     * 修改店铺列表
     */
    @PreAuthorize("@ss.hasPermi('shop:shop:edit')")
    @Log(title = "店铺列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TShop tShop) {
        tShop.setUpdateBy(getUsername());
        return toAjax(tShopService.updateTShop(tShop));
    }

    /**
     * 删除店铺列表
     */
    @PreAuthorize("@ss.hasPermi('shop:shop:remove')")
    @Log(title = "店铺列表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tShopService.deleteTShopByIds(ids));
    }

    @GetMapping("/all-list")
    public AjaxResult findShoplist() {
        List<TShop> list = tShopService.selectTShopList(null);
        return AjaxResult.success(list);
    }

}
